package com.wipz.eoa.iphone.dictionary;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wipz.eoa.iphone.BaseAction;
import com.wipz.eoa.iphone.IBaseService;
import com.wipz.eoa.iphone.businessProcess.AgencyCoreService;
import com.wipz.eoa.iphone.util.Constants;

public class DictionaryAction extends BaseAction{
	private IBaseService baseService;
	private AgencyCoreService agencyCoreService;
	private List workflowAgency;
	private List documentType;
	private List agencyMap;
	private List useAgenDept;
	private Map userAndDepariment;
	private List getSupliesType;
	private List sealName;
	
	public List getSealName() {
		return sealName;
	}

	public void setSealName(List sealName) {
		this.sealName = sealName;
	}

	public List getGetSupliesType() {
		return getSupliesType;
	}

	public void setGetSupliesType(List getSupliesType) {
		this.getSupliesType = getSupliesType;
	}

	public List getUseAgenDept() {
		return useAgenDept;
	}

	public void setUseAgenDept(List useAgenDept) {
		this.useAgenDept = useAgenDept;
	}
	
	public Map getUserAndDepariment() {
		return userAndDepariment;
	}

	public void setUserAndDepariment(Map userAndDepariment) {
		this.userAndDepariment = userAndDepariment;
	}


	public List getAgencyMap() {
		return agencyMap;
	}


	public void setAgencyMap(List agencyMap) {
		this.agencyMap = agencyMap;
	}


	public void setAgencyCoreService(AgencyCoreService agencyCoreService) {
		this.agencyCoreService = agencyCoreService;
	}
	

	public List getDocumentType() {
		return documentType;
	}

	public void setDocumentType(List documentType) {
		this.documentType = documentType;
	}

	public void setBaseService(IBaseService baseService) {
		this.baseService = baseService;
	}

	public List getWorkflowAgency() {
		return workflowAgency;
	}

	public void setWorkflowAgency(List workflowAgency) {
		this.workflowAgency = workflowAgency;
	}
	
	/**
	 * 单位字典
	 * @return
	 */
	public String workflowAgency() {
		workflowAgency = baseService.queryList("dictionary.Workflow_Agency", null);
		return SUCCESS;
	}
	
	/**
	 * 公文类型
	 * @return
	 */
	public String documentType() {
		documentType = baseService.queryList("officeDocumentType.queryById", null);
		return SUCCESS;
		}
	
	/**
	 * 所属单位
	 * @return
	 */
	public String agencyMap() {
		agencyMap = new ArrayList();
		String COMMITERCODE = (String) this.getSession().get(Constants.USERINFO_USERCODE);
		Map usermap = (Map) baseService.queryOne("user.queryUserList", COMMITERCODE);
		String userid = (String) usermap.get("ID");
		Map map = new HashMap();
		map = agencyCoreService.agencyList(Constants.SENDDOCUMENT_BUSINESS_ID, userid,map);	
		Map m = (Map) map.get("AGENCYMAP");
		String mp = m.toString().replace("{", "").replace("}", "");
		String[] str = mp.split(",");
		for(int i=0;i<str.length;i++) {
			Map m2 = new HashMap();
			String der = str[i];
			String[] s = der.split("=");
			if(s.length > 0) {
				m2.put("AGENCYID", s[0]);
				m2.put("NAME", s[1]);
			}
			agencyMap.add(m2);
		}
		return SUCCESS;
	}
	
	/**
	 * 用户单位信息
	 * @return
	 */
	public String userAndDepariment() {
		userAndDepariment = new HashMap();
		String COMMITERCODE = (String) this.getSession().get(Constants.USERINFO_USERCODE);
		String loginname = (String) baseService.queryOne("user.queryName", COMMITERCODE);
		userAndDepariment.put("COMMITER", loginname);
		//String department = (String) baseService.queryOne("agency.queryAgencyNamebycode", COMMITERCODE);
		String userid = (String) baseService.queryOne("user.queryId", COMMITERCODE);
		Map department =  (Map) baseService.queryOne("agency.queryAgencyByUserID", userid);
		if(null != department) {
		String deparmentname = (String) department.get("NAME");
		userAndDepariment.put("DEPARTMENT", deparmentname);
		}
		return SUCCESS;
	}
	
	public String sealName() {
		Map sealmap = new HashMap();
		sealmap.put("sealcode",this.getRequest().getParameter("sealcode"));
		sealName = baseService.queryList("dic.sealDic", sealmap);
		return SUCCESS;
	}
	
	/**
	 * 主办责任人
	 * @return
	 */
	public String useAgenDept() {
		useAgenDept = baseService.queryList("dictionary.Workflow_UseAgenDept", null);
		return SUCCESS;
	}
	
	/**
	 *办公用品类型
	 * @return
	 */
	public String getSupliesType() {
		getSupliesType = baseService.queryList("categoryDic.querylist", null);
		return SUCCESS;
	}
	
	/*
	 * 费用类型
	 */
	public List getCostType;
	public List getGetCostType() {
		return getCostType;
	}

	public void setGetCostType(List getCostType) {
		this.getCostType = getCostType;
	}

	public String getCostType() {
		getCostType = baseService.queryList("trafficDic.querylist", null);
		return SUCCESS;
	}
	
}
